const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;


void async function () {
    let n = Number(await readline());
    let range = []
    for (let i = 0; i < n; i++) {
        let line = await readline()
        let list = line.split(' ').map(Number)
        range.push( [list[0], list[1]] )
    }
    // 按照左端点排序，若左端点相同，则按右端点排序
    range.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
    let count = 0;
    for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
            let [lu, ru] = range[i]
            let [lv, rv] = range[j]
            if (Math.min(ru, rv) >= Math.max(lu, lv)) {
                count++
            }
            else if(ru < lv) {
                break
            }
        }
    }

    console.log(count);
}();
